/*
 * HecConwersionBean.java
 *
 * Created on 7 grudzie  2007, 08:11
 */
package PacEditor.Swing;

/**
 * @author Miki
 */
public class HecConwersionBean extends javax.swing.JPanel {

    /**
     * Creates new form HecConwersionBean
     */
    public HecConwersionBean() {
        initComponents();
    }

    private byte[] _bytes;
    private int _begin = 0;
    private int _end = 0;

    public synchronized int getBeginPoint() {
        return _begin;

    }

    public synchronized int getEndPoint() {
        return _end;
    }

    public synchronized void setBeginPoint(int _beg) {
        _begin = _beg;
        change();
    }

    public synchronized void setEndPoint(
            int _end1) {
        _end = _end1;
        change();
    }

    public synchronized byte[] getBytes() {
        return _bytes;
    }

    public synchronized void setBytes(byte[] _bytess) {
        _bytes = _bytess;

    }

    private String ConvertToInt() {
        String _ret = "";
        for (int t = _begin; t < _end; t++) {
            String _ret1 = "" + ((int) _bytes[t] & 0xff);
            for (int i = _ret1.length(); i < 3; i++) _ret1 = "0" + _ret1;

            _ret += _ret1 + "  ";

        }
        return _ret;
    }

    private String ConvertToHex() {
        String _ret = "";
        for (int t = _begin; t < _end; t++) {
            int b = _bytes[t] & 0xff;
            String _ret1 = Integer.toHexString(b).toUpperCase();
            for (int i = _ret1.length(); i < 2; i++) {
                _ret1 = "0" + _ret1;
            }

            _ret += _ret1 + "  ";
        }
        return _ret;
    }

    private String ConvertToStr() {
        StringBuffer _ret = new StringBuffer();
        for (int a = _begin; a < _end; a++) {
            int t1 = _bytes[a];
            if (t1 > 0x1f && t1 < 0x80) {
                _ret.append((char) t1);
            } else {
                _ret.append('.');
            }
        }

        return _ret.toString();
    }

    private void change() {
        String _hex = ConvertToHex();
        String _dec = ConvertToInt();
        String _str = ConvertToStr();
        jTextFieldDec.setText(_dec);
        jTextFieldHex.setText(_hex);
        jTextFieldStr.setText(_str);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextFieldHex = new javax.swing.JTextField();
        jTextFieldDec = new javax.swing.JTextField();
        jTextFieldStr = new javax.swing.JTextField();
        jLabelHex = new javax.swing.JLabel();
        jLabelDec = new javax.swing.JLabel();
        jLabelStr = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Hex Conwersions"));

        jTextFieldHex.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        jTextFieldHex.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldHexActionPerformed(evt);
            }
        });

        jTextFieldDec.setText("jTextField2");
        jTextFieldDec.setBorder(javax.swing.BorderFactory.createCompoundBorder());
        jTextFieldDec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldDecActionPerformed(evt);
            }
        });

        jTextFieldStr.setText("jTextField3");
        jTextFieldStr.setBorder(javax.swing.BorderFactory.createCompoundBorder());

        jLabelHex.setLabelFor(jTextFieldHex);
        jLabelHex.setText("Hex");

        jLabelDec.setText("Dec");

        jLabelStr.setText("Str");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabelHex)
                                .addComponent(jLabelDec)
                                .addComponent(jLabelStr))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextFieldStr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldDec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldHex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTextFieldHex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jTextFieldDec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabelDec, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jTextFieldStr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabelStr)))
                                .addComponent(jLabelHex, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(14, 14, 14))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldHexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldHexActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldHexActionPerformed

    private void jTextFieldDecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldDecActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldDecActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelDec;
    private javax.swing.JLabel jLabelHex;
    private javax.swing.JLabel jLabelStr;
    private javax.swing.JTextField jTextFieldDec;
    private javax.swing.JTextField jTextFieldHex;
    private javax.swing.JTextField jTextFieldStr;
    // End of variables declaration//GEN-END:variables
}
